<template>
  <div>
    <el-divider></el-divider>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="name" label="姓名" width="180" align="center"
                       show-overflow-tooltip></el-table-column>
      <el-table-column prop="phone" label="手机号" align="center" width="180"
                       show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="houseName" label="房源名称" align="center"
                       show-overflow-tooltip></el-table-column>
      <el-table-column prop="price" label="房源价格" align="center"
                       show-overflow-tooltip></el-table-column>
      <el-table-column prop="dateTime" label="预约时间" align="center"
                       show-overflow-tooltip></el-table-column>
    </el-table>

    <div style="text-align: right; margin: 10px auto;">
      <el-pagination
          @current-change="changePage"
          layout="total, prev, pager, next"
          :total="total"
          :current-page="currentPage"
          :page-size="pageSize">
      </el-pagination>
    </div>

  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      total: 0,
      pageSize: 0,
      currentPage: 1,
    }
  },
  methods: {


    changePage(value) {
      this.$router.replace('?page=' + value);
      this.loadReservationList();

    },
    loadReservationList() {
      let page = this.$router.currentRoute.query.page;
      if (!page) {
        page = 1;
      }
      let url = 'http://localhost:9200/UHA/yuecha?page=' + page;

      this.axios.get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.tableData = jsonResult.data.list;
          this.total = jsonResult.data.total;
          this.pageSize = jsonResult.data.pageSize;
          this.currentPage = jsonResult.data.currentPage;
        } else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      });
    }
  },
  mounted() {
    this.loadReservationList();
  }
}
</script>
